package com.useenum;

/**
 * @ClassName UseEnum
 * @Description TODO
 * @Author ZhangY
 * @Date 2020/1/21 14:17
 * @Version 1.0.0
 */
public class UseEnum {
    public static void main(String[] args) {
        System.out.println(  DemoEnum.BLUE  );
        System.out.println(  Food.Coffee.BLACK_COFFEE  );
        System.out.println("-------------------------");
        DemoEnum color = DemoEnum.RED;
        new UseEnum().change(color);
        System.out.println("-------------------------");
        System.out.println(  DemoEnum.getName(2)  );
        System.out.println(  DemoEnum.valueOf("GREEN")  );
        System.out.println("-------------------------");
        for (DemoEnum value : DemoEnum.values()) {
            System.out.print(value+"::");
            System.out.print(value.name()+"::");  // .name()输出的是当前枚举的名称，而不是值
            System.out.print(value.ordinal()+"::");   //.ordinal()输出索引
            System.out.println();
        }
        System.out.println("-------------------------");
        DemoEnum demoEnum = DemoEnum.RED;
        System.out.println(demoEnum.getEnumName(demoEnum));
    }

    public void change(DemoEnum color){
        switch (color) {
            case BLUE:
                System.out.println(DemoEnum.BLUE);
                break;
            case RED:
                System.out.println(DemoEnum.RED);
                break;
            case GREEN:
                System.out.println(DemoEnum.GREEN);
                break;
            case YELLOW:
                System.out.println(DemoEnum.YELLOW);
                break;
            default:
                System.out.println("null");
        }
    }
}
